package com.ruoyi.stock2.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.stock2.domain.STOCK;
import com.ruoyi.stock2.service.ISTOCKService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 股票信息Controller
 * 
 * @author ruoyi
 * @date 2019-10-21
 */
@Controller
@RequestMapping("/stock2/STOCK")
public class STOCKController extends BaseController
{
    private String prefix = "stock2/STOCK";

    @Autowired
    private ISTOCKService sTOCKService;

    @RequiresPermissions("stock2:STOCK:view")
    @GetMapping()
    public String STOCK()
    {
        return prefix + "/STOCK";
    }

    /**
     * 查询股票信息列表
     */
    @RequiresPermissions("stock2:STOCK:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(STOCK sTOCK)
    {
        startPage();
        List<STOCK> list = sTOCKService.selectSTOCKList(sTOCK);
        return getDataTable(list);
    }

    /**
     * 导出股票信息列表
     */
    @RequiresPermissions("stock2:STOCK:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(STOCK sTOCK)
    {
        List<STOCK> list = sTOCKService.selectSTOCKList(sTOCK);
        ExcelUtil<STOCK> util = new ExcelUtil<STOCK>(STOCK.class);
        return util.exportExcel(list, "STOCK");
    }

    /**
     * 新增股票信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存股票信息
     */
    @RequiresPermissions("stock2:STOCK:add")
    @Log(title = "股票信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(STOCK sTOCK)
    {
        return toAjax(sTOCKService.insertSTOCK(sTOCK));
    }

    /**
     * 修改股票信息
     */
    @GetMapping("/edit/{symbol}")
    public String edit(@PathVariable("symbol") String symbol, ModelMap mmap)
    {
        STOCK sTOCK = sTOCKService.selectSTOCKById(symbol);
        mmap.put("sTOCK", sTOCK);
        return prefix + "/edit";
    }

    /**
     * 修改保存股票信息
     */
    @RequiresPermissions("stock2:STOCK:edit")
    @Log(title = "股票信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(STOCK sTOCK)
    {
        return toAjax(sTOCKService.updateSTOCK(sTOCK));
    }

    /**
     * 删除股票信息
     */
    @RequiresPermissions("stock2:STOCK:remove")
    @Log(title = "股票信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sTOCKService.deleteSTOCKByIds(ids));
    }
}
